package com.hkts.naturalgas.alarminformation.controller;

import com.hkts.naturalgas.alarminformation.entity.NaturalgasGateStation;
import com.hkts.naturalgas.alarminformation.service.INaturalgasGateStationService;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import com.hkts.naturalgas.utils.TestDataUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassNameNaturalgasDataContrast
 * @Description
 * @Author yck
 * @Date2020-09-18 14:00
 * @Version V1.0
 **/
@RestController
@RequestMapping("/instrumentdata/naturalgasDataContrast")
public class NaturalgasDataContrast {
    @Autowired
    public INaturalgasGateStationService iNaturalgasGateStationService;

    @GetMapping("/getAaturalgasDataContrast")
    @ResponseBody
    public Result<Object> getAaturalgasDataContrast(String[] gateArray,String category, String dateRange,String[] dateArray){
        Map<String, Object> map = new HashMap<String, Object>();
        Map<String, Object> data = new HashMap<String, Object>();
        for(int i=0;i<gateArray.length;i++){
            Map<String, Object> aaturalgasDataContrast = getAaturalgasDataContrast(gateArray[i], category, dateRange, dateArray);
            data.put(gateArray[i],aaturalgasDataContrast.get("result"));
            if(i==0){
                map.put("hoursArray",aaturalgasDataContrast.get("hoursArray"));
            }
            aaturalgasDataContrast.remove("hoursArray");
        }
        map.put("data",data);
        return ResultUtil.data(map);
    }
    public  Map<String,Object> getAaturalgasDataContrast(String gateStation,String category, String dateRange,String[] dateArray){
        SimpleDateFormat dd = new SimpleDateFormat("yyyy-MM-dd");
        Map<String, Object> map = new HashMap<String, Object>();
        List<Float> list=new ArrayList<Float>();
        if(category.equals("0")){
            //今日
            if(dateRange.equals("0")){
                List<String> todayHours = TestDataUtils.getTodayHours();
                map.put("hoursArray", todayHours);
                for(int i=0;i<todayHours.size();i++){
                    list.add(TestDataUtils.getHoursData());
                }
            }else if(dateRange.equals("1")){
                List<String> listHours = TestDataUtils.getListHours(dd.format(TestDataUtils.getYesterday()));
                map.put("hoursArray", listHours);
                for(int i=0;i<listHours.size();i++){
                    list.add(TestDataUtils.getHoursData());
                }
            }else if(dateRange.equals("2")){
                List<String> dateArray1 = TestDataUtils.getDateArray(7);
                map.put("hoursArray", dateArray1);
                for(int i=0;i<dateArray1.size();i++){
                    list.add(TestDataUtils.getDateData());
                }
            }else if(dateRange.equals("3")){
                List<String> dateArray1 = TestDataUtils.getDateArray(30);
                map.put("hoursArray", dateArray1);
                for(int i=0;i<dateArray1.size();i++){
                    list.add(TestDataUtils.getDateData());
                }
            }else if(dateRange.equals("4")){
                List<String> daysByTime = TestDataUtils.getDaysByTime(dateArray);
                map.put("hoursArray", daysByTime);
                for(int i=0;i<daysByTime.size();i++){
                    list.add(TestDataUtils.getDateData());
                }
            }
        }else if(category.equals("2")){
            if(dateRange.equals("0")){
                List<String> todayHours = TestDataUtils.getTodayHours();
                map.put("hoursArray", todayHours);
                list.add(TestDataUtils.getHoursData());
            }else if(dateRange.equals("1")){
                List<String> listHours = TestDataUtils.getListHours(dd.format(TestDataUtils.getYesterday()));
                map.put("hoursArray", listHours);
                list.add(TestDataUtils.getHoursData());
            }else if(dateRange.equals("2")){
                List<String> dateArray1 = TestDataUtils.getDateArray(7);
                map.put("hoursArray", dateArray1);
                for(int i=0;i<dateArray1.size();i++){
                    list.add(TestDataUtils.getHoursData());
                }
            }else if(dateRange.equals("3")){
                List<String> dateArray1 = TestDataUtils.getDateArray(30);
                map.put("hoursArray", dateArray1);
                for(int i=0;i<dateArray1.size();i++){
                    list.add(TestDataUtils.getHoursData());
                }
            }else if(dateRange.equals("4")){
                List<String> daysByTime = TestDataUtils.getDaysByTime(dateArray);
                map.put("hoursArray", daysByTime);
                for(int i=0;i<daysByTime.size();i++){
                    list.add(TestDataUtils.getHoursData());
                }
            }
        }
        map.put("result",list);
        return map;
    }
}
